<template>
  <div class="gameitem">
    <div class="game-top" @click="gategory(categorys.gtId)">
      <img :src="categorys.gtImg" alt="" />
      <div class="gameitem-text">
        <div>{{ categorys.gtName }}</div>
        <div>共{{ categorys.gtSize }}款</div>
      </div>
    </div>

    <div class="moregame" :class="{ changtop: indexs > 4 }">
      <div class="sanbox" :class="{ sanbox2: indexs > 4 }">
        <div class="changbottom" :class="{ triangle2: indexs > 4 }"></div>
      </div>
      <div class="moregame-top" @click="gategory(categorys.gtId)">
        更多{{ categorys.gtName }}游戏
        <img src="../../../assets/img/right.svg" alt="" />
      </div>

      <div class="moregame-bottom">
        <div
          v-for="(item, index) in list"
          :key="index"
          @click="goGame(item.giId)"
        >
          <img :src="item.giLogo" alt="" />
          <div>{{ item.giName }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getThreeGame } from "../../../network/gameCategory";

export default {
  name: "GameItem",
  props: {
    indexs: {
      type: Number,
    },
    categorys: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      list: "",
    };
  },
  created() {
    this.getGame(this.categorys.gtId);
  },

  methods: {
    gategory(id) {
      this.$router.push({ name: "类别", params: { id: id } });
    },
    getGame(gid) {
      getThreeGame(gid).then((res) => {
        this.list = res.data.data;
        console.log(res);
      });
    },
    goGame(id) {
      this.$router.push({ name: "详情", params: { id: id } });
    },
  },
};
</script>

<style>
.gameitem {
  width: 80%;
}

.game-top {
  width: 100%;
  display: flex;
  padding: 0.1rem 0.1rem 0.1rem 0.1rem;
  border-radius: 10px;
  background-color: rgb(245, 247, 250);
  align-items: center;
}

.game-top:hover {
  background-color: rgb(230, 247, 255);
  cursor: pointer;
}

.game-top img {
  width: 40%;
  height: 0.45rem;
  border-radius: 0.1rem;
}

.gameitem-text {
  padding-left: 0.2rem;
}

.gameitem-text div:nth-child(1) {
  font-size: 0.13rem;
  margin-bottom: 0.05rem;
}

.gameitem-text div:nth-child(2) {
  font-size: 0.08rem;
}

.sanbox {
  width: 2rem;
  position: absolute;
  left: 0.2rem;
  top: -32px;
  z-index: 999;
}

.sanbox2 {
  width: 2rem;
  position: absolute;
  left: 0.2rem;
  top: 1.2rem;
  z-index: 999;
}

.moregame {
  position: absolute;
  width: 2rem;
  height: 1.2rem;
  background-color: rgb(255, 255, 255);
  border-radius: 10px;
  box-shadow: 0px 0px 0.1rem #adacac;
  top: 0.75rem;
  z-index: 99;
  display: none;
}

.changtop {
  top: -1.3rem;
}

.moregame:hover {
  display: block;
}

.gameitem:hover .moregame {
  display: block;
}

.moregame-top {
  display: flex;
  align-items: center;
  font-size: 0.08rem;
  margin: 0.1rem 0 0.2rem 0.1rem;
  cursor: pointer;
}

.moregame-top img {
  width: 0.12rem;
  height: 0.12rem;
}

.moregame-bottom {
  display: flex;
  align-items: center;
  justify-content: space-around;
  text-align: center;
}

.moregame-bottom div {
  width: 25%;
  cursor: pointer;
}

.moregame-bottom img {
  width: 100%;
  border-radius: 20%;
}

.moregame-bottom div div {
  width: 100%;
  font-size: 0.08rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.changbottom {
  width: 0px;
  height: 0px;
  border: 16px solid rgb(255, 255, 255);
  border-top-color: transparent;
  border-left-color: transparent;
  border-right-color: transparent;
}

.triangle2 {
  width: 0px;
  height: 0px;
  border: 16px solid rgb(255, 255, 255);
  border-bottom-color: transparent;
  border-left-color: transparent;
  border-right-color: transparent;
}
</style>